#!/usr/bin/perl -w
use strict;

use FindBin;


print STDERR <<"HEADLINE";
888888888888888888888888888888888888888888888888888888888888888888888

    remove_fasta_format_from_chromosomes.pl

		removes line endings and angle brackets from fasta sequence files


888888888888888888888888888888888888888888888888888888888888888888888

HEADLINE

for my $file_name(@ARGV)
{
	print STDERR "Processing $file_name...\n";
	my $acc_line = '';
	my $seq = '';
	my $cnt_dots = 0;
	my $cnt_lines = 0;
	{
		open FA, "$file_name" or die "Error:\n\tCould not open '$file_name'\n";
		open OUT, ">$file_name.tmp" or die "Error:\n\tCould not open '$file_name.tmp'\n";
		print STDERR "\t[";
		$acc_line = <FA>;
		print OUT $acc_line;
		while (<FA>)
		{
			++$cnt_lines;
			if ($cnt_lines % 200000 == 0)
			{
				++$cnt_dots;
				print STDERR "\n\t" if ($cnt_dots % 50 == 0);
				print STDERR ".";
			}
			chomp;
			print OUT;
		}
		print STDERR "]\n";
	}

	unlink $file_name;
	rename("$file_name.tmp", $file_name);
}

